#!/bin/bash

# MCP服务器功能测试脚本

echo "🧪 MCP服务器功能测试"
echo "================================"

cd /Users/colinwang/workspace/project/mcp-go/demo2

# 编译MCP服务器
echo "🔨 编译MCP服务器..."
if ! go build -o mcpserver/mcpserver mcpserver/main.go; then
    echo "❌ 编译失败"
    exit 1
fi

echo "✅ 编译成功"
echo ""

# 测试1: 初始化
echo "📋 测试1: 初始化MCP服务器"
echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}' | ./mcpserver/mcpserver &
sleep 1
kill %1 2>/dev/null
echo ""

# 测试2: 获取工具列表
echo "📋 测试2: 获取工具列表"
echo '{"jsonrpc":"2.0","id":2,"method":"tools/list"}' | ./mcpserver/mcpserver
echo ""

# 测试3: 时间查询
echo "📋 测试3: 查询北京时间"
echo '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"get_time","arguments":{"location":"北京"}}}' | ./mcpserver/mcpserver
echo ""

echo "📋 测试4: 查询纽约时间"
echo '{"jsonrpc":"2.0","id":4,"method":"tools/call","params":{"name":"get_time","arguments":{"location":"纽约"}}}' | ./mcpserver/mcpserver
echo ""

# 测试5: 数学计算
echo "📋 测试5: 基本加法计算"
echo '{"jsonrpc":"2.0","id":5,"method":"tools/call","params":{"name":"calculate","arguments":{"expression":"15+27"}}}' | ./mcpserver/mcpserver
echo ""

echo "📋 测试6: 乘法计算"
echo '{"jsonrpc":"2.0","id":6,"method":"tools/call","params":{"name":"calculate","arguments":{"expression":"12*8"}}}' | ./mcpserver/mcpserver
echo ""

echo "📋 测试7: 平方根计算"
echo '{"jsonrpc":"2.0","id":7,"method":"tools/call","params":{"name":"calculate","arguments":{"expression":"sqrt(16)"}}}' | ./mcpserver/mcpserver
echo ""

echo "📋 测试8: 幂运算"
echo '{"jsonrpc":"2.0","id":8,"method":"tools/call","params":{"name":"calculate","arguments":{"expression":"pow(2,3)"}}}' | ./mcpserver/mcpserver
echo ""

echo "✅ 所有测试完成！"
echo "🚀 MCP服务器功能正常，可以使用 ./start-mcp.sh 启动服务器"
